//  检查记录列表
//  CheckNotesTableViewController.m
//  yilutongxing
//
//  Created by  Mac on 2017/5/6.
//  Copyright © 2017年 YZE. All rights reserved.
//

#import "CheckNotesTableViewController.h"
#import "AddNotesTableViewController.h"
#import "RPCheckNote.h"
#import "AddNotesTableViewController.h"

#define URL_Getchecknotes @"/api/reports/mine?page=0&size=10000"

@interface CheckNotesTableViewController ()
@property(nonatomic, strong) NSArray *checkArr;
@end

@implementation CheckNotesTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title=@"检查记录";
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"添加" style:UIBarButtonItemStylePlain target:self action:@selector(addAction)];
    UIImage *leftImage=[[UIImage imageNamed:@"返回"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem *leftButtonItem=[[UIBarButtonItem alloc]initWithImage:leftImage style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    self.navigationItem.leftBarButtonItem=leftButtonItem;
    
    //请求网络数据
    [[YZENetwork sharedInstace] getRequestWithUrl:[BASE stringByAppendingString:URL_Getchecknotes]
                                    parameters:nil
                                    delegate:self
                                    requestTag:1
                                    successBlock:^(id responseObject) {
        self.checkArr = [RPCheckNote mj_objectArrayWithKeyValuesArrayAdd:responseObject];
        [self.tableView reloadData];
    }];
}

- (void)viewWillAppear:(BOOL)animated{
    //请求网络数据
    [[YZENetwork sharedInstace] getRequestWithUrl:[BASE stringByAppendingString:URL_Getchecknotes]
                                       parameters:nil
                                         delegate:self
                                       requestTag:1
                                     successBlock:^(id responseObject) {
                                         self.checkArr = [RPCheckNote mj_objectArrayWithKeyValuesArrayAdd:responseObject];
                                         [self.tableView reloadData];
                                     }];
}

-(void)back{
    [self dismissViewControllerAnimated:YES completion:nil];
}
-(void)addAction{
    AddNotesTableViewController *v=[AddNotesTableViewController new];
    [self.navigationController pushViewController:v animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.checkArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    }
    RPCheckNote *checknote = self.checkArr[indexPath.row];
    cell.textLabel.text = checknote.checkTime;
    cell.detailTextLabel.text = checknote.hospitalDTO.name;
    cell.detailTextLabel.textColor=[UIColor colorWithRed:142/255.0 green:142/255.0 blue:142/255.0 alpha:255/255.0];
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    AddNotesTableViewController *v = [AddNotesTableViewController new];
    RPCheckNote *note = self.checkArr[indexPath.row];
    v.checknote = note;
    v.hospitalID = [NSString stringWithFormat:@"%ld", note.hospitalDTO.ID];
    v.hospitalName = note.hospitalDTO.name;
    v.createTime = note.checkTime;
    [self.navigationController pushViewController:v animated:YES];
}

@end
